<template>
  <view class="content">
    <qian-dao :list="list" :date="date" :time_key="time_key" @day_change="day_change_fun"
      @date_change="date_change_fun"></qian-dao>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        // 当前的日期
        date: "",
        openId : uni.getStorageSync('openid'),
        // 存放时间的key值
        time_key: "",
        // 已经签到的数据列表
        list: [],

        // // 存放时间的key值
        // time_key: "time",
        // // 已经签到的数据列表
        // list: [{
        //  time: "2020-05-10",
        // }, {
        //  time: "03-15",
        // }, {
        //  time: "20",
        // }, {
        //  time: "31"
        // }],
      }
    },
    onLoad() {
     // this.getList()
  this.getqiandao()
    },
    // 方法
    methods: {
       async getqiandao(){
         const { data } = await uni.$http.get('/integral/findClock?openId=' + this.openId)
         if(data.statusCode !== 200) {
           return
         } else {
           this.list = data.data
         }
      },
      
      
      // 签到
     async getList() {
       const { data } = await uni.$http.get('/integral/clock?openId='  + this.openId ) 
       console.log(data)
       if(data.statusCode !== 200 ) {
         return uni.$u.toast(data.message)
       }else {
         return uni.$u.toast(data.message)
       }
      },
      // 点击天
      day_change_fun(day) {
        console.log('我是点击的那一天' , day);

        // 存放时间的key值
        let time_key = this.time_key;

        // 如果今天没有签到(只签到今天的，如果只需要签到今天的可以这么写)
        if (!day.click && day.type == "today") {
         if (time_key) {
             let obj = {};
             obj[time_key] = day.nyr;
             this.list.push(obj);
         } else {
             this.list.push(day.nyr);
             this.getList()
             console.log('我是签到数据' , this.list)
         }
        }
         
        
      },
      // 日期改变时触发
      date_change_fun(date) {
        // 更新日期
        this.date = date;
        // 清空已经签到的列表
        //this.list = [];
        // 根据日期获取已经签到的列表然后赋值
        // 存放时间的key值
        let time_key = this.time_key;
        console.log("time_key" , time_key)
        if (time_key) {
          console.log("time_key22" , time_key)
            //this.getList()
        } else {
          console.log("time_key11" , time_key)
         //   this.getList()
        }
      },
    },
  }
</script>

<style lang="scss" scoped>
  .content {
    width: 100%;
    height: 100%;
    background-color: skyblue;
  }
</style>
